<template>
  <div>
    <el-table
      :data="orderList"
      style="width: 1151px;margin-left: 10px;margin-top: 10px"
      :header-cell-style="{'text-align':'center'}"
      :cell-style="{'text-align':'center'}"
      border
    >
      <el-table-column
        prop="createTime"
        label="日期"
        width="150"
      />
      <el-table-column
        prop="productName"
        label="申请人"
        width="200"
      />
      <el-table-column
        prop="userName"
        label="拜访理由"
        width="300"
      />
      <el-table-column
        prop="orderId"
        label="健康状态"
        width="200"
      >
        <template slot-scope="scope">
          <el-button v-if="scope.row.orderState===1" type="success" plain disabled>绿码</el-button>
          <el-button v-if="scope.row.orderState===2" type="danger" plain disabled>红码</el-button>
        </template>
      </el-table-column>
      <el-table-column
        label="操作"
        width="300"
      >
        <template slot-scope="scope">
          <el-button type="primary" @click="agree(scope.row.orderId)">同意来访</el-button>
          <el-button type="danger" @click="disagres(scope.row.orderId)">拒绝来访</el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import axios from 'axios'
export default {
  name: 'OrderManage',
  data() {
    return {
      orderList: [
        {
          createTime: '2021-1-1',
          productName: '小李',
          userName: '我是来找王总谈正事的，并且身体无异常状况',
          orderState: 1
        },
        {
          createTime: '2021-1-1',
          productName: '小李',
          userName: '我是维修空调的',
          orderState: 2
        },
        {
          createTime: '2021-1-1',
          productName: '小王',
          userName: '我是来喝茶的',
          orderState: 1
        },
        {
          createTime: '2021-1-1',
          productName: '小王',
          userName: '我是来找王总谈正事的',
          orderState: 1
        }
      ],
      updateOrder: {
        orderId: null,
        orderState: null
      }
    }
  },
  created() {
    var vm = this
    axios.get('http://47.108.167.67:10001/server/order/getAllProductOrder').then(function(resp) {
      vm.orderList = resp.data.data.list
    })
  },
  methods: {
    agree(id) {
      // console.log(id);
      this.updateOrder.orderId = id
      this.updateOrder.orderState = 2
      var vm = this
      axios.post('http://47.108.167.67:10001/server/order/updateOrderStateById', vm.updateOrder).then(function(resp) {
        if (resp.data.success) {
          vm.$message({
            message: '同意租聘',
            type: 'success'
          })
          vm.$router.go(0)
        }
      })
    },
    disagres(id) {
      this.updateOrder.orderId = id
      var vm = this
      axios.delete('http://47.108.167.67:10001/server/order/deleteOrder/' + vm.updateOrder.orderId).then(function(resp) {
        if (resp.data.success) {
          vm.$message({
            message: '拒绝申请申请',
            type: 'warning'
          })
          vm.$router.go(0)
        }
      })
    },
    success(id) {
      this.updateOrder.orderId = id
      this.updateOrder.orderState = 0
      var vm = this
      axios.post('http://47.108.167.67:10001/server/order/updateOrderStateById', vm.updateOrder).then(function(resp) {
        if (resp.data.success) {
          vm.$message({
            message: '归还成功',
            type: 'success'
          })
          vm.$router.go(0)
        }
      })
    },
    fail(id) {
      this.updateOrder.orderId = id
      this.updateOrder.orderState = 4
      var vm = this
      axios.post('http://47.108.167.67:10001/server/order/updateOrderStateById', vm.updateOrder).then(function(resp) {
        if (resp.data.success) {
          vm.$message({
            message: '归还失败',
            type: 'warning'
          })
          vm.$router.go(0)
        }
      })
    }
  }

}
</script>

<style scoped>

</style>
